package org.zjx.common.bean;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private static final long serialVersionUID = -4577255781088498763L;
    private static final int OK = 200;
    private static final int FAIL = 500;
    private static final int UNAUTHORIZED = 2;

    private T data; //服务端数据
    private int code = OK; //状态码
    private String msg = ""; //描述信息

    //APIS
    public static Result isOk() {
        return new Result();
    }

    public static Result isFail() {
        return new Result().code(FAIL);
    }

    public static Result isFail(Throwable e) {
        return isFail().msg(e);
    }

    public Result msg(Throwable e) {
        this.setMsg(e.toString());
        return this;
    }

    public Result data(T data) {
        this.setData(data);
        return this;
    }

    public Result code(int code) {
        this.setCode(code);
        return this;
    }


    //Constructors
    public Result() {

    }

    //Getter&Setters

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
